package models

import (
	"time"
)

type Shop struct {
	Id     int       `json:"Id"`
	Name   string    `json:"Name"`
	Price  float64   `json:"Price"`
	Weight int       `json:"Weight"`
	Num    int       `json:"Num"`
	Times  time.Time `json:"Times"`
}

func MysqlList(page int, pageSize int, name string) ([]Shop, int64, error) {
	var shop []Shop
	var total int64
	query := DB.Model(&Shop{})
	if name != "" {
		query = query.Where("Name like ?", "%"+name+"%")
	}
	if err = query.Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&shop).Error; err != nil {
		return nil, 0, err
	}
	return shop, total, nil
}
